<template>
  <div class="myContainer">        
     <el-row class="myTitleBorderBottom">
      <el-col :span="20" class="myLineHeight_40px">
        基本信息
      </el-col>
    </el-row>
    <el-form :model="detail" :rules="rules" ref="ruleForm">   	
       <el-row class="myMarginTop_10px">
     <el-col :span="3" class="myLeftMsg">    	
       所属小区：
      </el-col>
      <el-col :span="7">
      	
        <template>
          <el-select 
            v-model="area_id"
             :disabled="is_modifly"
            clearable
            placeholder="所属小区请选择">
            <el-option
              v-for="item in areaIdList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>        
      </el-col>
    </el-row> 	
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">      
         区域ID:
      </el-col>
      <el-col :span="7">       
            <el-input :readonly="is_modifly" v-model="access_area_id" placeholder="请输入区域ID"></el-input>          
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">       
         区域名称:
      </el-col>
      <el-col :span="7">     	
           <el-input placeholder="请输入区域名称" v-model="access_area_name" :readonly="is_modifly"></el-input>       
      </el-col>
    </el-row>
   <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">       
         区域掩码:
      </el-col>
      <el-col :span="7">     	
           <el-input placeholder="请输入区域掩码" v-model="access_area_mask" :readonly="is_modifly"></el-input>        
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">       
         区域描述:
      </el-col>
      <el-col :span="7">      	
           <el-input placeholder="请输入区域描述" v-model="access_area_des" type="textarea" :readonly="is_modifly"></el-input>      
      </el-col>
    </el-row>                  
    <el-row class="myMarginTop_10px">
      <el-col :span="7" :offset="3">
        <!--<el-button type="primary" class="myBgGreen" v-if="type=='update'" @click="onEditAd">保 存</el-button>
        <el-button type="primary" class="myBgGreen" v-if="type=='add'" @click="onCreate">权限下放</el-button>
        <el-button type="primary" class="myBgGreen" v-if="type=='update'" @click="onCreate">取消授权</el-button>-->
        <el-button type="primary" class="myBgGreen" @click="onBack">返 回</el-button>
      </el-col>
    </el-row>
  </el-form>  
    
  </div>
</template>
<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
    padding-right: 10px;
  }
  .myMarginTop_10px{
    padding-bottom: 10px;
  }
  .myVA_M{
    vertical-align: middle;
  }
  .myMarginBottom_10px{
    margin-bottom: 20px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
    border:1px solid #d8dce5;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
<script>
  import { getJumpValue , addAd , getAd , editAd } from '@/api/online';
  import { getAreaDetail } from '@/api/entrance_guard';
  import { r_email , r_phone } from "@/api/regular";//正则
  export default {
    data(){
      return{
        title: "区域管理",
        id: "",
        is_modifly:false,
        type:"",
        ad_name:"",
        detail:{
          
        },                              
        ADDESC:"",
        access_area_id:"",
        access_area_name:"",
        access_area_des:"",
        access_area_mask:"",
        area_id:"",
        areaIdList:[{value:0,label:"兰亭别院"},{value:1,label:"欧鹏k城"}],
        rules: {         
          card_no:[
            {required: true, message: '不能为空！', trigger: 'blur'},            
            ],          
        },
      }
    },
    components: {
        
    },
    created(){
      document.title=this.title;
      this.type = this.$route.query.type;
      this.id = this.$route.query.id;
      if(this.type=='add'){
      }
      if(this.type=='info'){
        this.onGetAd();
        this.is_modifly = true;
        this.is_disabled = true;
      }      
    },
    methods:{     
      onEditAd(){
        let vm=this;
        let params={          
          ADDESC:vm.ADDESC,        
        }
        editAd(params).then(response => {
          console.log("修改成功")
          this.$message.success('执行成功！');
          this.$router.go(-1);
        }).catch(error => {
          this.$message.error('执行失败！');
          console.log("修改失败")
        })
      },
      onCreate(){//添加
        let vm=this;
        let params={       
          ADDESC:vm.ADDESC,
        }
        addAd(params).then(response => {
          let res=response.data;
          vm.$message.success("添加数据成功！");
          this.$router.go(-1);
          console.log("添加成功",res);
        }).catch(error => {
          vm.$message.error("添加数据失败！");
          console.log("添加失败",error);
        })
        console.log(params)
      },
      onBack(){//返回
      	let vm =this;
      	window.localStorage.setItem('pageNum',vm.$route.query.pageNum||1);
        this.$router.go(-1);
      },
      
      onGetAd(){//拉取
          let vm=this;      
          getAreaDetail(vm.id).then(response => {
          let res=response.data;
          vm.access_area_id=res.access_area_id,
          vm.access_area_name=res.access_area_name,
          vm.access_area_des=res.access_area_des,
          vm.area_id=res.area_id,
          vm.access_area_mask=res.access_area_mask
        }).catch(error => {
          console.log("拉取数据失败",error);
        })
      } 
      

    }
  
  }


</script>



